﻿using System;

using System.Text;

/// <summary>
/// num_list 的摘要说明
/// </summary>
public class num_list
{
	public num_list()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public static int parse(string input, out string output)
    {
        int seg, min, max, total = 0, j;
        StringBuilder outbuf = new StringBuilder();
        string[] strArray;
        string[] tmp;
        strArray = input.Split(',');
        seg = strArray.GetLength(0);
        for (int i = 0; i < seg; i++)
        {
            tmp = strArray[i].Split('-');
            if (tmp.GetLength(0) <= 0 || tmp.GetLength(0) > 2)
            {
                output = "";
                return -1;
            }
            try
            {
                if (tmp.GetLength(0) == 1)
                {
                    min = Convert.ToInt16(tmp[0]);
                    max = min;
                }
                else
                {
                    min = Convert.ToInt16(tmp[0]);
                    max = Convert.ToInt16(tmp[1]);
                }
            }
            catch (Exception ex)
            {
                output = "";
                return -1;
            }
            for (j = min; j <= max; j++)
            {
                outbuf.Append(j.ToString() + ",");
                total++;
            }
        }
        output = outbuf.ToString();
        output = output.Substring(0, output.Length - 1);
        return total;
    }
}
